package day8;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class NextBirthday {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Calendar cal = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
//        c2.set(Calendar.HOUR,0);
//        c2.set(Calendar.MINUTE,0);
//        c2.set(Calendar.SECOND,0);
//        c2.set(Calendar.MILLISECOND,0);
        System.out.println("输入出生日期：");
        String birth = sc.next();
        int year = cal.get(Calendar.YEAR);
        String bir = year + "-" + birth+" 23:59:59";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd H:mm:ss");
        df.setLenient(false);
        int errNum = 0;
        Date nextDate = null;
        while (errNum <= 8) {
            try {
                nextDate = df.parse(bir);
                if (nextDate.compareTo(c2.getTime())>0) {
                    break;
                }
                errNum++;
                year++;
                bir = year + "-" + birth+" 23:59:59";
                continue;
            } catch (ParseException e) {
            }
            errNum++;
            year++;
            bir = year + "-" + birth+" 23:59:59";
        }
        if (errNum > 8) {
            System.out.println("生日输入错误");
            return;
        }
        System.out.println("下次过生日是：" + nextDate);
        int diff= (int) ((nextDate.getTime()-c2.getTimeInMillis())/1000/(60*60*24));
        System.out.println(diff);
    }
}
